package it.greg.findparty.android.ui;

import it.greg.findparty.R;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class EventDetailsActivity extends Activity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event_details);
		try {
			Intent intent = getIntent();
			TextView txtTitle = (TextView) findViewById(R.id.txtTitle);
			txtTitle.setText(intent.getStringExtra("titolo"));
			TextView txtData = (TextView) findViewById(R.id.txtData);
			String ora = intent.getStringExtra("ora");
			txtData.setText(intent.getStringExtra("data") + " - Ore: "+ora);
			TextView txtAddr = (TextView) findViewById(R.id.txtAddr);
			txtAddr.setText(intent.getStringExtra("indirizzo"));
			TextView txtDesc = (TextView) findViewById(R.id.txtDesc);
			txtDesc.setText(intent.getStringExtra("descrizione"));
			Button btnFbPage = (Button) findViewById(R.id.btnFbPage);
			btnFbPage.setOnClickListener(new View.OnClickListener() {
			    @Override
			    public void onClick(View v) {
			    	Intent intent = getIntent();
			        loadFbPage(intent.getStringExtra("fbpage"));
			    }
			});
		} catch(Exception e) {
			Toast.makeText(this, "Error:\n"+e.getMessage(), Toast.LENGTH_LONG).show();
		}

	}
	
	private void loadFbPage(String url){
		Intent i = new Intent(Intent.ACTION_VIEW);
		Uri u = Uri.parse(url);
		try {
			// Start the activity
			i.setData(u);
			startActivity(i);
		} catch (ActivityNotFoundException e) {
			// Raise on activity not found
			Toast.makeText(this, "Browser not found.", Toast.LENGTH_SHORT).show();
		}
	}

}
